package com.useeinfo.oa.modules.inspection.entity;

import com.alibaba.fastjson.JSONObject;
import com.useeinfo.framework.extend.entity.SuperClassEntity;
import com.useeinfo.framework.sugar.tools.DateTimeUtils;
import com.useeinfo.framework.sugar.tools.StringConverters;
import com.useeinfo.oa.modules.base.entity.Enterprise;
import com.useeinfo.oa.modules.inspection.enums.InsOrderOperationEnum;
import com.useeinfo.oa.modules.security.entity.SystemUser;

import javax.persistence.*;

/**
 * @Description: 计划工单日志表
 */
@Entity
@Table(name = "planner_inspection_log")
public class PlannerInspectionLog extends SuperClassEntity<PlannerInspectionLog> {

    /**
     * 操作人
     */
    @ManyToOne
    @JoinColumn(name = "user_id")
    private SystemUser systemUser;

    /**
     * 操作人姓名
     */
    private String userName;

    /**
     * 详情
     */
    private String detail;

    /**
     * 操作
     */
    @Enumerated(value = EnumType.STRING)
    @Column(name = "order_operation")
    private InsOrderOperationEnum insOrderOperationEnum;

    /**
     * 计划工单
     */
    @ManyToOne
    @JoinColumn(name = "planner_order_id")
    private PlannerInspection plannerInspection;

    /**
     * 关联企业
     */
    @ManyToOne
    @JoinColumn(name = "enterprise_id")
    private Enterprise enterprise;

    public SystemUser getSystemUser() {
        return systemUser;
    }

    public void setSystemUser(SystemUser systemUser) {
        this.systemUser = systemUser;
    }

    public String getUserName() {
        return userName;
    }

    public void setUserName(String userName) {
        this.userName = userName;
    }

    public String getDetail() {
        return detail;
    }

    public void setDetail(String detail) {
        this.detail = detail;
    }

    public InsOrderOperationEnum getInsOrderOperationEnum() {
        return insOrderOperationEnum;
    }

    public void setInsOrderOperationEnum(InsOrderOperationEnum insOrderOperationEnum) {
        this.insOrderOperationEnum = insOrderOperationEnum;
    }

    public PlannerInspection getPlannerInspection() {
        return plannerInspection;
    }

    public void setPlannerInspection(PlannerInspection plannerInspection) {
        this.plannerInspection = plannerInspection;
    }

    public Enterprise getEnterprise() {
        return enterprise;
    }

    public void setEnterprise(Enterprise enterprise) {
        this.enterprise = enterprise;
    }

    @Override
    public JSONObject toJSONObject() {
        JSONObject jsonObject = super.toJSONObject();
        jsonObject.put("orderOperationEnum", StringConverters.null2String(getInsOrderOperationEnum().getName()));
        jsonObject.put("plannerInspection", StringConverters.null2String(getPlannerInspection().getName()));
        jsonObject.put("detail", StringConverters.null2String(getDetail()));
        jsonObject.put("userName", StringConverters.null2String(getUserName()));
        jsonObject.put("enterprise", StringConverters.null2String(getEnterprise().getEnterpriseName()));
        jsonObject.put("createDate", DateTimeUtils.formatDateToStringWithTime(getCreateDate()));



        return jsonObject;
    }


}
